#include <iostream>
#include "map.h"
#include <conio.h>
#include <Windows.h>
#include <time.h>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
using namespace std;

void Menu();
void Introduce(); 

int main(int argc, char** argv) {
	Map map1(15), map2(30), map3(50);

	map1.Creat(15);
	map2.Creat(30);
	map3.Creat(50);

	int choice1;
	char choice2,choice3,choice4;
	bool Isgo_on = false, judge[3] = { };
	cout << "\n\t\t欢迎来到老鼠迷宫！";
	cout << "\t\t请按任意键继续";
	getch(); 
//	for(int i = 0;i < 4;i ++){
//		Sleep(500);
//		cout << ".";
//	} 
	system("cls");
	Introduce();
	system("cls");
	Menu();
	cout << "请输入您的选择：";
	cin >> choice1;
	while(1){
		switch(choice1){
			
			case 1:
				int i;
				again:
				cout << "请输入您要挑战的关卡：" ;
				cin >> i;

				if(i == 1){
					system("cls");
					map1.Display();
					judge[0] = map1.Move();
					if(judge[0] == true){
						map1.Visite();
						cout << "是否继续闯关？ y\n" << endl;
						cin >> choice3;
						if(choice3 == 'y'){
							goto again;
						} 
						else {
							break;
						}
					}	
					else{
					system("pause");
					break;
					}	
				}
				else if(i == 2){
					system("cls");
					map2.Display();
					judge[1] = map2.Move();
					if(judge[1] == true){
						map2.Visite();
						cout << "是否继续闯关？ y\n" << endl;
						cin >> choice3;
						if(choice3 == 'y'){
							goto again;
						} 
						else {
							break;
						}
					}	
					else{
					system("pause");
					break;
					}	
				}
				else if(i == 3){
					system("cls");
					map3.Display();
					judge[2] = map3.Move();
					if(judge[2] == true){
						map3.Visite();
						cout << "是否继续闯关？ y\n" << endl;
						cin >> choice3;
						if(choice3 == 'y'){
							goto again;
						} 
						else{
							break;
						}
					}	
					else{
					system("pause");
					break;
					}	
				}
				else{
					cout << "输入错误" << endl;
					system("pause");
					break;
				}
			case 2:
				system("cls");
				cout << "请输入要编辑的关卡: \n";
				cout << "1.第一关" << endl;
				cout << "2.第二关" << endl;
				cout << "3.第三关" << endl; 
				cin >> choice4;
				if(choice4 == '1' && judge[0] == true){
					map1.Change();
				}
				else if(choice4 == '2' && judge[1] == true){
					map2.Change();
				}
				else if(choice4 == '3' && judge[2] == true ){
					map3.Change();
				}
				else{
					cout << "未通过关卡，不能进行编辑" << endl;
					system("pause");
				}
				break;
			case 3:
				system("cls");
				cout << "请输入要查看答案的关卡: \n";
				cout << "1.第一关" << endl;
				cout << "2.第二关" << endl;
				cout << "3.第三关" << endl;
				cin >> choice4;
				if (choice4 == '1'){
					map1.ShowPath();
				}
				else if (choice4 == '2') {
					map2.ShowPath();
				}
				else if (choice4 == '3') {
					map3.ShowPath();
				}
				else {
					cout << "输入错误!" << endl;
					system("pause");
				}
				break;

			case 4:
				system("cls");
				cout << "\n\t\t是否退出游戏？ y\n" << endl;
				cin >> choice2;
				if(choice2 == 'y'){
					return 0;
				}
				else if(choice2 == 'n'){
					break;
				}
			default:
				 cout << "\t\t输入无效，请按任意键继续" << endl;
				 getch();
				 break;
				}
		system("cls");
		Menu();
		cout << "\n\t\t请输入您的选择" << endl;
		cin >> choice1;
	}
}

void Menu(){
	cout << "\n\t\t**********************************" << endl; 
	cout << "\t\t*                                  *" << endl;
	cout << "\t\t*         小鼠走迷宫游戏           *" << endl; 
	cout << "\t\t*          1、开始游戏             *" << endl;
	cout << "\t\t*          2、编辑地图             *" << endl;
	cout << "\t\t*          3、查看答案             *" << endl;
	cout << "\t\t*          4、退出游戏             *" << endl;
	cout << "\t\t*                                  *" << endl;
	cout << "\t\t************************************" << endl; 
}

void Introduce(){
	system("cls");
	cout << "\n\t\t**********************************" << endl;
	cout << "\t\t*             玩法介绍             *" << endl;
	cout << "\t\t*  1.玩家通过w,a,s,d控制小鼠的移动 *" << endl;
	cout << "\t\t*  2.玩家可通过w,a,s,d进行地图编辑 *" << endl;
	cout << "\t\t*                                  *" << endl;
	cout << "\t\t************************************" << endl;
	getch();
}

















